// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.asset;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import zombie.core.textures.ImageData;
import zombie.core.textures.TextureIDAssetManager;
import zombie.debug.DebugOptions;
import zombie.fileSystem.FileSystem;
import zombie.fileSystem.FileTask;
import zombie.fileSystem.IFileTaskCallback;

public final class FileTask_LoadImageData extends FileTask {
    String m_image_name;
    boolean bMask = false;

    public FileTask_LoadImageData(String imageName, FileSystem fs, IFileTaskCallback cb) {
        super(fs, cb);
        this.m_image_name = imageName;
    }

    @Override
    public String getErrorMessage() {
        return this.m_image_name;
    }

    @Override
    public void done() {
    }

    public Object call() throws Exception {
        TextureIDAssetManager.instance.waitFileTask();
        if (DebugOptions.instance.AssetSlowLoad.getValue()) {
            try {
                Thread.sleep(500L);
            } catch (InterruptedException interruptedException) {
            }
        }

        FileInputStream fileInputStream = new FileInputStream(this.m_image_name);

        ImageData imageData;
        try {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);

            try {
                imageData = new ImageData(bufferedInputStream, this.bMask);
            } catch (Throwable throwable0) {
                try {
                    bufferedInputStream.close();
                } catch (Throwable throwable1) {
                    throwable0.addSuppressed(throwable1);
                }

                throw throwable0;
            }

            bufferedInputStream.close();
        } catch (Throwable throwable2) {
            try {
                fileInputStream.close();
            } catch (Throwable throwable3) {
                throwable2.addSuppressed(throwable3);
            }

            throw throwable2;
        }

        fileInputStream.close();
        return imageData;
    }
}
